package org.darkforest.merchant.factory;

import org.darkforest.enums.AjaxAlbumTypeEnum;
import org.darkforest.merchant.ajaxTemplete.AlbumAjaxPage;
import org.darkforest.merchant.ajaxTemplete.impl.GoodsStep2DescAlbum;
import org.darkforest.merchant.ajaxTemplete.impl.GoodsStep2ImageAlbum;
import org.darkforest.merchant.ajaxTemplete.impl.GoodsStep2MobileAlbum;
import org.darkforest.merchant.ajaxTemplete.impl.GoodsStep3GalleryAlbum;
import org.darkforest.model.AlbumClass;
import org.darkforest.model.AlbumPicPageBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by valentina on 15/3/19.
 */
@Component
public class AlbumAjaxCodeFactory {

    private static Logger logger = LoggerFactory.getLogger(AlbumAjaxCodeFactory.class);


//    @Autowired
//    private static IAlbumClassService albumClassService;
//
//
//    private static List<AlbumClass> getAlbumClassList(Integer storeId){
//        return albumClassService.getAlbumClassList(storeId);
//    }

    private static AlbumAjaxPage getAlbumAjaxPage(String insertType){
        AlbumAjaxPage ajaxPage = null;
        //商品主图
        if(AjaxAlbumTypeEnum.IMAGE.getText().equals(insertType)){
            return new GoodsStep2ImageAlbum();
        }
        //详情编辑器
        if(AjaxAlbumTypeEnum.EDITOR.getText().equals(insertType)){
            return new GoodsStep2DescAlbum();
        }
        //移动端编辑器
        if(AjaxAlbumTypeEnum.MOBILE.getText().equals(insertType)){
            return new GoodsStep2MobileAlbum();
        }
        //步骤三gallery
        if(AjaxAlbumTypeEnum.GALLERY.getText().equals(insertType)){
            return new GoodsStep3GalleryAlbum();
        }
        return ajaxPage;
    }

    /**
     *
     * @param basePath
     * @param albumClassList
     * @param picPage
     * @param insertType
     * @return
     * @throws NullPointerException
     */
    public static String getAlbumAjaxCode(String basePath,List<AlbumClass> albumClassList,AlbumPicPageBean picPage,AjaxAlbumTypeEnum insertType,Integer specSize) throws NullPointerException{
        if(albumClassList==null || insertType==null){
            throw new NullPointerException("");
        }
        AlbumAjaxPage page = getAlbumAjaxPage(insertType.getText());
        logger.debug("get album page:"+page.getClass().getName());
        return page.getAlbumCode(basePath,albumClassList,picPage,specSize);
    }


}
